<?php
require_once($application_folder."/controllers/navigator.php");
class Wordofday extends Navigator{

    function __construct(){
        parent::__construct();
        
        /************************************************************
        * CHECK LOGIN
        *************************************************************/
        if(!$this->session->userdata('logged_in')){
            redirect(base_url());
        }
        
        $this->load->helper('date');
    }

    function index(){
        $this->preview();
    }

    function preview(){
        
        /************************************************************
        * GET Caricature
        *************************************************************/
        $data['wordofday'] = $this->db->get('wordofday')->result_array();

        $this->core_cms('wordofday', $data, 'preview');                                  
    }

    function newform(){
        
        $data = array();
        
        /************************************************************
        * GET Caricature if Edit MODE
        *************************************************************/
        if(isset($_GET['id'])){
            $data['wordofday'] = $this->db->get_where('wordofday', array('id' => $_GET['id']))->result_array();    
        }
        

        $this->core_cms('wordofday', $data, 'new_edit_form');                                  
    }
    
    function edit_insert(){
        
        
        switch ($_POST['appmode']){
            
            case 'insert':
            $this->db->insert('wordofday', array('author' => $_POST['author'], 'text' => $_POST['text'], 'datetime' => strtotime($_POST['datetime'])));
            echo json_encode(array('action'=> true)); 
            break;
            
            case 'edit':
            
            $this->db->where('id', $_POST['id']);
            $this->db->update('wordofday', array('author' => $_POST['author'], 'text' => $_POST['text'], 'datetime' => strtotime($_POST['datetime'])));
            
            echo json_encode(array('action'=> true));
            
            break;
            
        }
        
    }
    
    function deleteone(){
        
        $this->db->where('id',$_POST['id']);
        $this->db->delete('wordofday');
        echo json_encode(array('action'=> true));
    }

}